package com.ynet.eq.haiqing.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ynet.eq.aop.comfig.AopDemo;
import com.ynet.eq.aop.repeatedsubmit.NoRepeatSubmit;
import com.ynet.eq.aop.syslog.SysLog;
import com.ynet.eq.common.exception.ResponseEntity;
import com.ynet.eq.haiqing.crud.entity.Log;
import com.ynet.eq.haiqing.crud.service.LogService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author 胡超雄
 * @date 2021/6/22 17:58
 * @desc
 */
@RestController
@RequestMapping("/demo")
@AopDemo
public class demo {

    @Resource
    private LogService logService;


    @PostMapping("/community_tree_no_pro")
    @SysLog("试试sql 是否能够自动填充")
    public ResponseEntity communityTreeNoPro(TestBean req) {
//        Log log =new Log();
//        log.setIp("1747");
//        log.setMethod("Get");
//        log.setOperation("胡超雄的测试操作修改");
//        log.setTime(1747L);
//        log.setCreatedAt(new Date());
//        log.setCreatedBy("Mr.H");
//        logService.saveOrUpdate(log);
//        List<Log> list = logService.list();
//
        System.out.println("正常代码开始工作");
        return ResponseEntity.ok("测试成功");
    }

    @GetMapping("/community_tree_no_pro2")
    @NoRepeatSubmit(seconds = 10)
  //  @SysLog("测试是否能全部删除")
    public ResponseEntity communityTreeNoPro2(TestBean req) {

        QueryWrapper<Log> lQw =new QueryWrapper<>();
        lQw.isNull("changed_at");
        Page<Log> page = new Page<>(1, 10);
        Page<Log> page1 = logService.page(page, lQw);
        return ResponseEntity.ok(page1);
    }

    public static void main(String[] args) {
        String name = new TestBean().getClass().getName();

        List<String> a = new ArrayList<>();
        System.out.println(name);
    }


}
